﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADA.Entity;
using ADA.Business;

namespace ADA.Presentation
{
    public partial class ChangePassForm : Form
    {
        private Admin ad;
        bool flag;

        public ChangePassForm(Admin Ad)
        {
            ad = Ad;
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            validate();
            if (flag == false) return;
            string message;
            BOLAccount bolAcc = new BOLAccount();

            string oldPass = tbxOldPass.Text.Trim();
            string newPass = tbxNewPass.Text.Trim();
            if (bolAcc.changePass(ad, oldPass, newPass, out message)==true)
            {
                this.Close();
                return;
            }
            else
            {
                lblError.Text = message;
                return;
            }
        }

        private void ChangePassForm_Load(object sender, EventArgs e)
        {
            tbxOldPass.Select();
            lblError.Text = "";
        }

        private void validate()
        {
            flag = true;
            if ((tbxNewPass.Text.Trim() == ""))
            {
                errorNewPass.SetError(tbxNewPass, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorNewPass.Clear();
            }
            if ((tbxOldPass.Text.Trim() == ""))
            {
                errorOldPass.SetError(tbxOldPass, Common.MESSAGE_ERROR_MUST_INPUT_DATA);
                flag = false;
            }
            else
            {
                errorOldPass.Clear();
            }
            if (tbxConfirmPass.Text.Trim().Equals(tbxNewPass.Text) == false)
            {
                errorConfirmPass.SetError(tbxConfirmPass, Common.MESSAGE_ERROR_CONFIRM_PASSWORD_INCORECT);
                flag = false;
            }
            else
            {
                errorConfirmPass.Clear();
            }
        }
    }
}
